var copyRandomList = function (head) {
  if (head == null) return head;
  let map = new Map(),
    curr = head;
  while (curr) {
    let newNode = new Node(curr.val);
    map.set(curr, newNode);
    curr = curr.next;
  }

  curr = head;
  while (curr) {
    let newNode = map.get(curr);
    let next = map.get(curr.next);
    let random = map.get(curr.random);
    if (next) newNode.next = next;
    if (random) newNode.random = random;
    curr = curr.next;
  }
  return map.get(head);
};
